package com.huitian.mobileshop;

import java.math.BigDecimal;
import java.util.HashMap;

public class ProductContainer {

	private final static HashMap<String, Integer> products=new HashMap<String, Integer>();
	private static BigDecimal totalprice=new BigDecimal("0");
	
	
	public static void clear(){
		products.clear();
		totalprice=new BigDecimal("0");
	}
	
	public static boolean isEmpty(){
		return products.size()==0?true:false;
	}
	
	
	public static String plus(String productcode,float price){
		
		if(products.containsKey(productcode)){
			int value=products.get(productcode);
			products.put(productcode, value+1);
		}else{
			products.put(productcode, 1);
		}
		totalprice=totalprice.add(new BigDecimal(price+""));
		return ProductContainer.totalprice.toString();
		
	}
	
	public static String sub(String productcode,float price){
		if(products.containsKey(productcode)&&products.get(productcode)>0){
			int value=products.get(productcode);
			products.put(productcode, value-1);
			ProductContainer.totalprice=ProductContainer.totalprice.subtract(new BigDecimal(price+""));
		}
		return totalprice.toString();
	}

	public static HashMap<String, Integer> products() {
		// TODO Auto-generated method stub
		return products;
	}
	
}
